import { WarScoreView } from "../guildWar/WarScoreView";
import { NationalTreasureInfo } from "../../model/NationalTreasureInfo";
import { Language } from "../../../../extend/language/Language";
import { Cache } from "../../cache/Cache";
import { NationalTreaCampScoreView } from "./NationalTreaCampScoreView";
import { ItemsUtil } from "../shortcuts/item/ItemsUtil";
import { HTMLUtil } from "../../../../com/gengine/utils/HTMLUtil";
import { SecTimer } from "../../../../com/gengine/core/frame/SecTimer";
import { TimerType } from "../../../../com/gengine/core/frame/TimerType";
import { AIManager } from "../../scene/ai/AIManager";
import { AIType } from "../../scene/ai/AIType";
import { GTextFiled } from "../../../../com/mui/controls/GTextFiled";
import { GlobalStyle } from "../../../common/global/GlobalStyle";
import { FilterConst } from "../../../component/gconst/FilterConst";
import { GButton } from "../../../../com/mui/controls/GButton";
import { SecTimerView } from "../common/SecTimerView";
import { NetDispatcher } from "../../../mvc/core/NetDispatcher";
import { ServerCommand } from "../../mvc/ServerCommand";
type int = number;
//class NationalTreaScoreView
    
    export  class NationalTreaScoreView extends WarScoreView
    {
        constructor()
        {
            super();
            if (NationalTreaScoreView._instance) 
            {
                throw new Error("NationalTreaScoreView is single!");
            }
            return;
        }

        protected /* override */ initSize(): void
        {
            super.initSize();
            _bgH = 208;
            return;
        }

        public updateHonor(arg1: int): void
        {
            this._honorValue.text = arg1 + "";
            return;
        }

        public updateData(arg1: NationalTreasureInfo): void
        {
            this._info = arg1;
            this.updateCampInfo(arg1);
            if (arg1.playerInfo) 
            {
                this._roleVal1.text = arg1.playerInfo.seizure.toString();
                this._roleVal2.text = arg1.playerInfo.guard.toString();
            }
            this._honorValue.text = arg1.honor + "";
            if (arg1.activeTime) 
            {
                this._leftTime.text = Language.getString(27014);
                this._timeValue.setLeftTime(arg1.timeLeft);
            }
            else if (arg1.checkInStart) 
            {
                if (arg1.dateDis > 0) 
                {
                    this._leftTime.text = Language.getString(27015);
                    this._timeValue.timeOutHandler = this.onTimeOutHandler;
                    this._timeValue.setLeftTime(arg1.dateDis);
                }
                else 
                {
                    this._leftTime.text = Language.getString(27014);
                    this._timeValue.setLeftTime(arg1.timeLeft);
                }
            }
            else 
            {
                this._leftTime.text = Language.getString(27014);
                this._timeValue.setLeftTime(0);
            }
            if (Cache.instance.nationalTrea.isSeizeCamp()) 
            {
                this._gotoGet.label = Language.getString(27006);
                if (_spContent.contains(this._gotoHand)) 
                {
                    _spContent.removeChild(this._gotoHand);
                }
            }
            else 
            {
                this._gotoGet.label = Language.getString(27005);
                if (!_spContent.contains(this._gotoHand)) 
                {
                    _spContent.addChild(this._gotoHand);
                }
            }
            return;
        }

        public updateCampInfo(arg1: NationalTreasureInfo): void
        {
            var loc1=arg1.getMyCampInfo();
            if (loc1) 
            {
                this._totalVal.text = (loc1.rest + loc1.guard + loc1.seize).toString();
                this._leftVal.text = loc1.rest.toString();
                this._campVal1.text = loc1.seize.toString();
                this._campVal2.text = loc1.guard.toString();
            }
            if (!NationalTreaCampScoreView.instance.isHide) 
            {
                NationalTreaCampScoreView.instance.updateData(arg1);
            }
            return;
        }

        /* internal  */onTimeOutHandler(): void
        {
            if (this._info) 
            {
                this._leftTime.text = Language.getString(27014);
                this._timeValue.setLeftTime(this._info.timeLeft);
            }
            return;
        }

        protected onRolePackItemChange(arg1: Object): void
        {
            var loc1=ItemsUtil.getNationalTreaItemNum();
            this._packVal.htmlText = HTMLUtil.addColor(loc1 + " / " + this._maxRoleNum, "#ffff00");
            if (loc1 >= this._maxRoleNum) 
            {
                this.startFlashTxt();
            }
            else 
            {
                this.stopFlashTxt();
            }
            return;
        }

        protected startFlashTxt(): void
        {
            if (!this._timer) 
            {
                this._timer = new SecTimer(1);
                this._timer.addListener(TimerType.ENTERFRAME, this.onTimerHandler);
            }
            if (!this._timer.running) 
            {
                this._timer.start();
            }
            return;
        }

        protected stopFlashTxt(): void
        {
            if (this._timer && this._timer.running) 
            {
                this._timer.stop();
                this._timer.isDelete = false;
            }
            return;
        }

        protected onTimerHandler(arg1: SecTimer): void
        {
            if (arg1.repeatCount % 2 != 0) 
            {
                this._packVal.htmlText = HTMLUtil.addColor(this._packVal.text, "#ff0000");
            }
            else 
            {
                this._packVal.htmlText = HTMLUtil.addColor(this._packVal.text, "#00ff00");
            }
            return;
        }

        /* internal  */onGoToGetClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=Cache.instance.scene.getNearlyNationalBoss();
            if (loc1) 
            {
                if (Cache.instance.nationalTrea.isSeizeCamp()) 
                {
                    AIManager.onAutoPathAIControl(loc1, AIType.AI_Scene);
                }
                else 
                {
                    AIManager.onAutoPathAIControl(loc1, AIType.AI_Entity);
                }
            }
            return;
        }

        /* internal  */onGoToHandClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=Cache.instance.scene.getNearlyNationalTaskNPC();
            if (loc1) 
            {
                AIManager.onAutoPathAIControl(loc1);
            }
            return;
        }

        protected /* override */ initUI(): void
        {
            super.initUI();
            _spContent.mouseChildren = true;
            this._campInfoTxt = new GTextFiled();
            this._campInfoTxt.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._campInfoTxt.width = 100;
            this._campInfoTxt.textColor = GlobalStyle.color1Uint;
            this._campInfoTxt.filters = [FilterConst.nameGlowFilter];
            this._campInfoTxt.text = "★" + Language.getString(27009);
            this._campInfoTxt.x = 18;
            this._campInfoTxt.y = 5;
            this._campInfoTxt.selectable = false;
            _spContent.addChild(this._campInfoTxt);
            this._totalTxt = new GTextFiled();
            this._totalTxt.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._totalTxt.width = 100;
            this._totalTxt.textColor = GlobalStyle.color1Uint;
            this._totalTxt.filters = [FilterConst.nameGlowFilter];
            this._totalTxt.htmlText = HTMLUtil.addColor(Language.getString(27016), GlobalStyle.color1);
            this._totalTxt.x = this._campInfoTxt.x + 12;
            this._totalTxt.y = this._campInfoTxt.y + 20;
            this._totalTxt.selectable = false;
            _spContent.addChild(this._totalTxt);
            this._totalVal = new GTextFiled();
            this._totalVal.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._totalVal.width = 100;
            this._totalVal.textColor = 16776960;
            this._totalVal.filters = [FilterConst.nameGlowFilter];
            this._totalVal.text = "0";
            this._totalVal.x = this._totalTxt.x + this._totalTxt.textWidth;
            this._totalVal.y = this._totalTxt.y;
            this._totalVal.selectable = false;
            _spContent.addChild(this._totalVal);
            this._leftTxt = new GTextFiled();
            this._leftTxt.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._leftTxt.width = 100;
            this._leftTxt.textColor = GlobalStyle.color1Uint;
            this._leftTxt.filters = [FilterConst.nameGlowFilter];
            this._leftTxt.text = Language.getString(27008);
            this._leftTxt.x = this._totalTxt.x;
            this._leftTxt.y = this._totalTxt.y + 20;
            this._leftTxt.selectable = false;
            _spContent.addChild(this._leftTxt);
            this._leftVal = new GTextFiled();
            this._leftVal.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._leftVal.width = 100;
            this._leftVal.textColor = 16776960;
            this._leftVal.filters = [FilterConst.nameGlowFilter];
            this._leftVal.text = "0";
            this._leftVal.x = this._totalVal.x;
            this._leftVal.y = this._leftTxt.y;
            this._leftVal.selectable = false;
            _spContent.addChild(this._leftVal);
            this._campTxt1 = new GTextFiled();
            this._campTxt1.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._campTxt1.width = 100;
            this._campTxt1.textColor = 16763906;
            this._campTxt1.filters = [FilterConst.nameGlowFilter];
            this._campTxt1.text = Language.getString(27005) + "：";
            this._campTxt1.x = this._leftTxt.x;
            this._campTxt1.y = this._leftTxt.y + 20;
            this._campTxt1.selectable = false;
            _spContent.addChild(this._campTxt1);
            this._campVal1 = new GTextFiled();
            this._campVal1.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._campVal1.width = 80;
            this._campVal1.textColor = 16763906;
            this._campVal1.filters = [FilterConst.nameGlowFilter];
            this._campVal1.text = "0";
            this._campVal1.x = this._campTxt1.x + this._campTxt1.textWidth;
            this._campVal1.y = this._campTxt1.y;
            this._campVal1.selectable = false;
            _spContent.addChild(this._campVal1);
            this._campTxt2 = new GTextFiled();
            this._campTxt2.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._campTxt2.width = 100;
            this._campTxt2.textColor = 65280;
            this._campTxt2.filters = [FilterConst.nameGlowFilter];
            this._campTxt2.text = Language.getString(27006) + "：";
            this._campTxt2.x = 95;
            this._campTxt2.y = this._campTxt1.y;
            this._campTxt2.selectable = false;
            _spContent.addChild(this._campTxt2);
            this._campVal2 = new GTextFiled();
            this._campVal2.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._campVal2.width = 100;
            this._campVal2.textColor = 65280;
            this._campVal2.filters = [FilterConst.nameGlowFilter];
            this._campVal2.text = "0";
            this._campVal2.x = this._campTxt2.x + this._campTxt2.textWidth;
            this._campVal2.y = this._campTxt2.y;
            this._campVal2.selectable = false;
            _spContent.addChild(this._campVal2);
            this._roleInfoTxt = new GTextFiled();
            this._roleInfoTxt.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._roleInfoTxt.width = 100;
            this._roleInfoTxt.textColor = GlobalStyle.color1Uint;
            this._roleInfoTxt.filters = [FilterConst.nameGlowFilter];
            this._roleInfoTxt.text = "★" + Language.getString(27010);
            this._roleInfoTxt.x = this._campInfoTxt.x;
            this._roleInfoTxt.y = this._campVal2.y + 20;
            this._roleInfoTxt.selectable = false;
            _spContent.addChild(this._roleInfoTxt);
            this._honorTxt = new GTextFiled();
            this._honorTxt.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._honorTxt.width = 100;
            this._honorTxt.textColor = 16763906;
            this._honorTxt.filters = [FilterConst.nameGlowFilter];
            this._honorTxt.text = Language.getString(30012);
            this._honorTxt.x = this._roleInfoTxt.x + 12;
            this._honorTxt.y = this._roleInfoTxt.y + 20;
            this._honorTxt.selectable = false;
            _spContent.addChild(this._honorTxt);
            this._honorValue = new GTextFiled();
            this._honorValue.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._honorValue.width = 100;
            this._honorValue.textColor = 16763906;
            this._honorValue.filters = [FilterConst.nameGlowFilter];
            this._honorValue.text = "0";
            this._honorValue.x = this._honorTxt.x + this._honorTxt.textWidth;
            this._honorValue.y = this._honorTxt.y;
            this._honorValue.selectable = false;
            _spContent.addChild(this._honorValue);
            this._roleTxt1 = new GTextFiled();
            this._roleTxt1.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._roleTxt1.width = 100;
            this._roleTxt1.textColor = 16763906;
            this._roleTxt1.mouseEnabled = false;
            this._roleTxt1.filters = [FilterConst.nameGlowFilter];
            this._roleTxt1.text = Language.getString(27005) + "：";
            this._roleTxt1.x = this._honorTxt.x;
            this._roleTxt1.y = this._honorTxt.y + 20;
            _spContent.addChild(this._roleTxt1);
            this._roleVal1 = new GTextFiled();
            this._roleVal1.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._roleVal1.width = 80;
            this._roleVal1.textColor = 16763906;
            this._roleVal1.filters = [FilterConst.nameGlowFilter];
            this._roleVal1.text = "0";
            this._roleVal1.x = this._roleTxt1.x + this._roleTxt1.textWidth;
            this._roleVal1.y = this._roleTxt1.y;
            this._roleVal1.selectable = false;
            _spContent.addChild(this._roleVal1);
            this._roleTxt2 = new GTextFiled();
            this._roleTxt2.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._roleTxt2.width = 100;
            this._roleTxt2.textColor = 65280;
            this._roleTxt2.mouseEnabled = false;
            this._roleTxt2.filters = [FilterConst.nameGlowFilter];
            this._roleTxt2.text = Language.getString(27006) + "：";
            this._roleTxt2.x = this._campTxt2.x;
            this._roleTxt2.y = this._roleTxt1.y;
            _spContent.addChild(this._roleTxt2);
            this._roleVal2 = new GTextFiled();
            this._roleVal2.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._roleVal2.width = 100;
            this._roleVal2.textColor = 65280;
            this._roleVal2.filters = [FilterConst.nameGlowFilter];
            this._roleVal2.text = "0";
            this._roleVal2.x = this._roleTxt2.x + this._roleTxt2.textWidth;
            this._roleVal2.y = this._roleTxt2.y;
            this._roleVal2.selectable = false;
            _spContent.addChild(this._roleVal2);
            this._packTxt = new GTextFiled();
            this._packTxt.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._packTxt.width = 100;
            this._packTxt.textColor = GlobalStyle.color1Uint;
            this._packTxt.filters = [FilterConst.nameGlowFilter];
            this._packTxt.text = Language.getString(27013);
            this._packTxt.x = this._roleInfoTxt.x + 12;
            this._packTxt.y = this._roleTxt2.y + 20;
            this._packTxt.selectable = false;
            _spContent.addChild(this._packTxt);
            this._packVal = new GTextFiled();
            this._packVal.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._packVal.width = 100;
            this._packVal.textColor = 16776960;
            this._packVal.filters = [FilterConst.nameGlowFilter];
            this._packVal.text = "0 / 5";
            this._packVal.x = 115;
            this._packVal.y = this._packTxt.y;
            this._packVal.selectable = false;
            _spContent.addChild(this._packVal);
            this._gotoGet = new GButton();
            this._gotoGet.label = Language.getString(27005);
            this._gotoGet.styleName = "ButtonMini";
            this._gotoGet.setSize(40, 20);
            this._gotoGet.textField.filters = [FilterConst.nameGlowFilter];
            this._gotoGet.addEventListener(flash.events.MouseEvent.CLICK, this.onGoToGetClickHandler);
            this._gotoGet.x = this._packTxt.x;
            this._gotoGet.y = this._packVal.y + 20;
            _spContent.addChild(this._gotoGet);
            this._gotoHand = new GButton();
            this._gotoHand.label = Language.getString(27054);
            this._gotoHand.styleName = "ButtonMini";
            this._gotoHand.setSize(40, 20);
            this._gotoHand.textField.filters = [FilterConst.nameGlowFilter];
            this._gotoHand.addEventListener(flash.events.MouseEvent.CLICK, this.onGoToHandClickHandler);
            this._gotoHand.x = this._campTxt2.x;
            this._gotoHand.y = this._gotoGet.y;
            _spContent.addChild(this._gotoHand);
            this._leftTime = new GTextFiled();
            this._leftTime.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._leftTime.width = 100;
            this._leftTime.textColor = GlobalStyle.color1Uint;
            this._leftTime.filters = [FilterConst.nameGlowFilter];
            this._leftTime.text = Language.getString(27014);
            this._leftTime.x = this._packTxt.x;
            this._leftTime.y = this._packTxt.y + 40;
            this._leftTime.selectable = false;
            _spContent.addChild(this._leftTime);
            this._timeValue = new SecTimerView();
            this._timeValue.x = this._packVal.x;
            this._timeValue.y = this._leftTime.y;
            this._timeValue.setParse(HTMLUtil.addColor("hh: mm: ss", "#00ff00"));
            this._timeValue.mouseEnabled = false;
            this._timeValue.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._timeValue.height = 20;
            _spContent.addChild(this._timeValue);
            return;
        }

        protected /* override */ onShowDetailsHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            super.onShowDetailsHandler(arg1);
            if (NationalTreaCampScoreView.instance.isHide) 
            {
                NationalTreaCampScoreView.instance.show();
                NationalTreaCampScoreView.instance.updateData(Cache.instance.nationalTrea.nationalInfo);
            }
            else 
            {
                NationalTreaCampScoreView.instance.hide();
            }
            return;
        }

        public /* override */ show(arg1: int=0, arg2: int=0): void
        {
            super.show(arg1, arg2);
            NetDispatcher.addCmdListener(ServerCommand.BackpackDataChange, this.onRolePackItemChange);
            NetDispatcher.addCmdListener(ServerCommand.BackPackItemsChange, this.onRolePackItemChange);
            this.onRolePackItemChange(null);
            this._totalTxt.toolTipData = HTMLUtil.addColor(Language.getString(27017), "#ffffff");
            this._totalVal.toolTipData = HTMLUtil.addColor(Language.getString(27017), "#ffffff");
            this._leftTxt.toolTipData = HTMLUtil.addColor(Language.getString(27018), "#ffffff");
            this._leftVal.toolTipData = HTMLUtil.addColor(Language.getString(27018), "#ffffff");
            this._campTxt1.toolTipData = HTMLUtil.addColor(Language.getString(27019), "#ffffff");
            this._campVal1.toolTipData = HTMLUtil.addColor(Language.getString(27019), "#ffffff");
            this._campTxt2.toolTipData = HTMLUtil.addColor(Language.getString(27020), "#ffffff");
            this._campVal2.toolTipData = HTMLUtil.addColor(Language.getString(27020), "#ffffff");
            this._packTxt.toolTipData = HTMLUtil.addColor(Language.getString(27021), "#ffffff");
            this._packVal.toolTipData = HTMLUtil.addColor(Language.getString(27021), "#ffffff");
            return;
        }

        public /* override */ hide(): void
        {
            super.hide();
            NetDispatcher.removeCmdListener(ServerCommand.BackpackDataChange, this.onRolePackItemChange);
            NetDispatcher.removeCmdListener(ServerCommand.BackPackItemsChange, this.onRolePackItemChange);
            this.stopFlashTxt();
            this._timeValue.dispose();
            this._totalTxt.toolTipData = null;
            this._totalVal.toolTipData = null;
            this._leftTxt.toolTipData = null;
            this._leftVal.toolTipData = null;
            this._campTxt1.toolTipData = null;
            this._campVal1.toolTipData = null;
            this._campTxt2.toolTipData = null;
            this._campVal2.toolTipData = null;
            this._packTxt.toolTipData = null;
            this._packVal.toolTipData = null;
            return;
        }

        public static get instance(): NationalTreaScoreView
        {
            if (!NationalTreaScoreView._instance) 
            {
                NationalTreaScoreView._instance = new NationalTreaScoreView();
            }
            return NationalTreaScoreView._instance;
        }

        /* internal */ /* var */_packTxt: GTextFiled;

        /* internal */ /* var */_packVal: GTextFiled;

        /* internal */ /* var */_leftTime: GTextFiled;

        /* internal */ /* var */_timeValue: SecTimerView;

        /* internal */ /* var */_leftVal: GTextFiled;

        /* internal */ /* var */_gotoHand: GButton;

        /* internal */ /* var */_info: NationalTreasureInfo;

        /* internal */ /* var */_campInfoTxt: GTextFiled;

        /* internal */ /* var */_totalTxt: GTextFiled;

        /* internal */ /* var */_gotoGet: GButton;

        /* internal */ /* var */_totalVal: GTextFiled;

        /* internal */ /* var */_maxRoleNum: int=5;

        /* internal */ /* var */_leftTxt: GTextFiled;

        protected /* var */_timer: SecTimer;

        /* internal */ /* var */_campTxt1: GTextFiled;

        /* internal */ /* var */_campVal1: GTextFiled;

        /* internal */ /* var */_campTxt2: GTextFiled;

        /* internal */ /* var */_campVal2: GTextFiled;

        /* internal */ /* var */_roleInfoTxt: GTextFiled;

        /* internal */ /* var */_honorTxt: GTextFiled;

        /* internal */ /* var */_roleVal2: GTextFiled;

        /* internal */ /* var */_honorValue: GTextFiled;

        /* internal */ /* var */_roleTxt1: GTextFiled;

        /* internal */ /* var */_roleVal1: GTextFiled;

        /* internal */ static /* var */_instance: NationalTreaScoreView;

        /* internal */ /* var */_roleTxt2: GTextFiled;
    }
